﻿using Medicine.Entity;
using Medicine.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/// <summary>
/// 用户的实体层
/// </summary>
namespace Medicine.Dao
{
    class UserDao
    {
        /// <summary>
        /// 进行数据的验证
        /// </summary>
        /// <param name="u">待验证的数据</param>
        public void check(User u)
        {
            String sql = "select * from user_table where number='" + u.Number + "'and passwd='" + u.Passwd + "'";
            DataSet ds=DbHelper.query(sql);
            DataTable dt = ds.Tables[0];
            //判断是否检测到了数据
            if (dt.Rows.Count > 0)
            {//获取读取到的数据
                u.Id = (int)dt.Rows[0][0]; u.Name = dt.Rows[0][1].ToString(); u.Number = dt.Rows[0][2].ToString();
                u.Passwd = dt.Rows[0][3].ToString();
                if (dt.Rows[0][4] == null)
                    u.Price = 0;
                else
                u.Price = float.Parse(dt.Rows[0][4].ToString());
                u.Authority = (int)dt.Rows[0][5];
            }//没有获取到数据
            else
            {
                u.Id = -1;
            }
        }
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="u">user的实体</param>
        public void insert(User u)
        {
            String sql = "insert into user_table(name,number,passwd,authority,end_price) values('" + u.Name + "','" + u.Number + "','" + u.Passwd + "','" + u.Authority + "','" + u.Price + "')";
            DbHelper.insert(sql);
        }

        public void updateInfo(String sql)
        {
            DbHelper.query(sql);
        }
    }
}
